package com.oocl.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.oocl.dao.CustFavsDao;
import com.oocl.formV1.util.DBUtil;

public class CustFavsDaoImpl implements CustFavsDao{

	@Override
	public int addCustFavs(Integer cust_id, List<Integer> favs_ids) {
		String sql = "insert into cust_favo(id, cust_id, favo_id) values(cust_favo_Seq.nextval, ?, ?)";
		Connection con=null;
		PreparedStatement pst = null;
		int m = 0;
		try {
			con=DBUtil.getConnection();
			pst = con.prepareStatement(sql);
			for(Integer fId:favs_ids){
				pst.setInt(1, cust_id);
				pst.setInt(2, fId);
				m = pst.executeUpdate();
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.close(null, pst, null);
		}
		return m;
	}

	@Override
	public boolean delByCustId(int cust_id) {
		String sql = "delete from cust_favo where cust_id = ?";
		Connection con = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		try {
			con=DBUtil.getConnection();
			pst = con.prepareStatement(sql);
			pst.setInt(1, cust_id);
			rs = pst.executeQuery();
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		finally{
			DBUtil.close(null, pst, rs);
		}
		return false;
	}

	
}
